package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.custom.BlueLoadingProgress;
import com.cz.nongyetongv5.utils.CharsetUtil;
import com.cz.nongyetongv5.utils.ConfigUtil;

public class ChaXunActivity extends Activity implements OnClickListener {

	private ViewGroup btnBack = null;

	private BlueLoadingProgress blpLoading = null;

	private ViewGroup btnSearch = null;

	private EditText edtChaXunFilter = null;

	private WebView wvChaXun = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.chaxun);

		wvChaXun = (WebView) findViewById(R.id.wvChaXun);

		// �Զ�����ͼƬ
		wvChaXun.getSettings().setLoadsImagesAutomatically(true);
		// ���ýű�
		wvChaXun.getSettings().setJavaScriptEnabled(true);

		wvChaXun.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {

				if (blpLoading != null) {

					blpLoading.stopLoading();

					blpLoading.setVisibility(View.GONE);
				}

			}
		});

		blpLoading = (BlueLoadingProgress) findViewById(R.id.blpLoading);
		blpLoading.setVisibility(View.GONE);

		btnBack = (ViewGroup) findViewById(R.id.btnBack);
		btnBack.setOnClickListener(this);

		btnSearch = (ViewGroup) findViewById(R.id.btnSearch);
		btnSearch.setOnClickListener(this);

		edtChaXunFilter = (EditText) findViewById(R.id.edtChaXunFilter);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		if (v == btnBack) {
			finish();
		}

		if (v == btnSearch) {

			if (CharsetUtil.isNotNull(edtChaXunFilter.getText().toString())) {
				blpLoading.setVisibility(View.VISIBLE);

				String url = new ConfigUtil(getResources()).getPreHttpUrl()
						+ getString(R.string.touyongpin_chaxun_url)
						+ edtChaXunFilter.getText().toString().trim();

				blpLoading.setVisibility(View.VISIBLE);

				wvChaXun.loadUrl(url);

			}
		}

	}

}
